package com.itheima.myCalendar;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Demo1 {
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        System.out.println("c = " + c);

        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        String time = sdf.format(date);
        System.out.println(time);

/*
     常见日历字段:
        年: public static final int YEAR = 1;
        月: public static final int MONTH = 2;
        日: public static final int DATE = 5;

     int get(int field):  返回给定日历字段的值。

 */
        //获取当前日历的年份
        int year = c.get(Calendar.YEAR);
        System.out.println("year = " + year);

        //获取当前日历的月份
        int month = c.get(Calendar.MONTH);
        //注意: Calendar中月份从0开始,取值范围: 0~11,+1是能获得真正的月份
        System.out.println("month = " + (month + 1));

        //获取当前日历的日期【本月的第几天】
        int day1 = c.get(Calendar.DATE);
        System.out.println("day1 = " + day1);
        //【本年的第几天】
        int day2 = c.get(Calendar.DAY_OF_YEAR);
        System.out.println("day2 = " + day2);
    }
}
